// -----------------------------------------------------------------------
//  <copyright file="ClaimIdentityExtensions.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2024 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://www.dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2024-03-04 23:33</last-date>
// -----------------------------------------------------------------------

using System.Security.Claims;


namespace DaprPlus.Identity;

public static class ClaimIdentityExtensions
{
    /// <summary>
    /// 获取角色Id
    /// </summary>
    public static string[] GetRoles(this IIdentity identity)
    {
        Check.NotNull(identity, nameof(identity));
        if (identity is not ClaimsIdentity claimsIdentity)
        {
            return [];
        }
        var names = claimsIdentity.FindAll(claimsIdentity.RoleClaimType).Select(c => c.Value).ToArray();
        return names;
    }
}
